<template>
  <el-container>
    <!-- 头部 -->
    <el-header>
      <div class="header">
        <div class="header-left">
          <span
            v-if="!isFold"
            style="font-size: 22px; "
          >物联网管理后台界面</span>
          <span
            v-else
            class="el-icon-eleme"
          ></span>
          <span
            class="fold-btn"
            :class="foldIcon"
            @click="changeFold"
          ></span>
        </div>
        <div class="header-right">
          <span style="font-size: 18px">这里煤球</span>
          <span class="iconfont icon-tuichu"></span>
        </div>
      </div>
    </el-header>
    <el-container>
      <!-- 左侧导航 -->
      <el-aside :width="`${asideWidth}px`">
        <el-menu
          :default-active="defaultPath"
          class="el-menu-vertical-demo"
          background-color="#2932da"
          text-color="#fff"
          active-text-color="#ffd04b"
          style="border: 0"
          :collapse="isFold"
          router
        >
          <el-menu-item index="/deviceList">
            <i class="el-icon-menu"></i>
            <span slot="title">设备管理</span>
          </el-menu-item>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-search"></i>
              <span>日志查询</span>
            </template>
            <el-menu-item index="/deviceLog">
              <span slot="title">设备日志</span>
            </el-menu-item>
            <el-menu-item index="/ledLog">
              <span slot="title">板载灯日志</span>
            </el-menu-item>
            <el-menu-item index="/tempHumidityLog">
              <span slot="title">温湿度日志</span>
            </el-menu-item>
            <el-menu-item index="/infraredLog">
              <span slot="title">红外检测日志</span>
            </el-menu-item>
          </el-submenu>
          <el-menu-item index="/userList">
            <i class="el-icon-user-solid"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 右侧内容 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      foldIcon: "el-icon-s-fold",
      isFold: false,
      asideWidth: 200,
      defaultPath: location.pathname,
    };
  },
  methods: {
    changeFold() {
      this.isFold = !this.isFold;
      this.foldIcon = this.isFold ? "el-icon-s-unfold" : "el-icon-s-fold";
      this.asideWidth = this.isFold ? 60 : 200;
    },
  },
};
</script>

<style scoped>
.el-container {
  height: 100%;
}
.el-header {
  background-color: #3a60df;
  color: rgb(255, 247, 247);
  transition: all 0.5s;
}
.el-aside {
  background-color: #2932da;
  color: rgb(255, 247, 247);
  transition: all 0.5s;
  font-size: 20px;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0px 20px;
  height: 100%;
}
.header-left span {
  font-size: 22px;
  margin-right: 20px;
}
.header-left:first-child {
  font-weight: bold;
  user-select: none;
  cursor: default;
}
.fold-btn {
  cursor: pointer;
}
</style>
